package cn.supermarket.controller;

import cn.supermarket.pojo.dto.AddSupplierDTO;
import cn.supermarket.pojo.dto.SupplierSimpleDTO;
import cn.supermarket.pojo.vo.SupplierInfoVO;
import cn.supermarket.service.iservice.ISupplierService;
import cn.supermarket.web.JsonPage;
import cn.supermarket.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/supplier")
@Api(tags = "供货商业务模块")
public class SupplierController {

    @Autowired
    private ISupplierService supplierService;

    @GetMapping("/add")
    @ApiOperation("添加供货商")
    public JsonResult<String> addSupplier(AddSupplierDTO addSupplierDTO){
        supplierService.addSupplier(addSupplierDTO);
        return JsonResult.ok("添加完成!");
    }

    @GetMapping("/select/page")
    @ApiOperation("分页查询供货商信息")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "名字",name = "name",dataType = "string"),
            @ApiImplicitParam(value = "页码",name = "pageNum",dataType = "int"),
            @ApiImplicitParam(value = "每页条数",name = "pageSize",dataType = "int")})
    public JsonResult<JsonPage<SupplierInfoVO>> getSupplierInfo(String name, Integer pageNum, Integer pageSize){
        JsonPage<SupplierInfoVO> supplierInfo = supplierService.getSupplierInfo(name,pageNum, pageSize);
        return JsonResult.ok(supplierInfo);
    }

    @PostMapping("/update/supplier")
    @ApiOperation("修改供货商信息")
    public JsonResult updateSupplier(Long id,SupplierSimpleDTO supplierSimpleDTO){
        supplierService.updateSupplierInfo(id,supplierSimpleDTO);
        return JsonResult.ok("修改完成!");
    }

    @PostMapping("/delete")
    @ApiOperation("注销供货商信息")
    public JsonResult deleteSupplier(Long id){
        supplierService.cancelSupplier(id);
        return JsonResult.ok("已注销该供货商!");
    }
}
